home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 424_02 / ED-157 / autowrp.c < prev    next >
C/C++ Source or Header  |  1993-09-10  |  2KB  |  59 lines

  1. /*
  2.  * Copyright (C) 1992 by Rush Record (rhr@clio.rice.edu)
  3.  * 
  4.  * This file is part of ED.
  5.  * 
  6.  * ED is free software; you can redistribute it and/or modify it under the terms
  7.  * of the GNU General Public License as published by the Free Software Foundation.
  8.  * 
  9.  * ED is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  10.  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  11.  * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  12.  * 
  13.  * You should have received a copy of the GNU General Public License along with ED
  14.  * (see the file COPYING).  If not, write to the Free Software Foundation, 675
  15.  * Mass Ave, Cambridge, MA 02139, USA.
  16.  */
  17. #include "opsys.h"
  18.  
  19. #include "ctyp_dec.h"
  20. #include "rec.h"
  21. #include "window.h"
  22. #include "ed_dec.h"    /* global data */
  23. #include "keyvals.h"
  24.  
  25. /******************************************************************************\
  26. |Routine: autowrp
  27. |Callby: edit
  28. |Purpose: Handles autowrapping when cursor moves past wrap margin. Returns 1 if
  29. |         autowrapping was possible, otherwise 0.
  30. |Arguments:
  31. |    keybuf is the key they just pressed.
  32. \******************************************************************************/
  33. Int autowrp(keybuf)
  34. Schar keybuf;
  35. {
  36.     register Int j,k,nspaces,nleft;
  37.     
  38.     for(j = CURBYT;j > 0;j--)    /* find a blank char backwards from current position */
  39.         if(isspace(CURREC->data[j - 1]) && (j <= WRAP_MARGIN + 1))
  40.             break;
  41.     if(j)    /* if no blank chars, skip it */
  42.     {
  43.         nleft = CURBYT - j;    /* number of times to move left before starting to delete blanks */
  44.         for(k = j - 1;k > 0;k--)    /* find a nonblank char backwards from blank char */
  45.             if(!isspace(CURREC->data[k - 1]))
  46.                 break;
  47.         nspaces = j - k;    /* number of blank chars to delete */
  48.         emulate_key((Schar)KEY_LEFTARROW,nleft);    /* load nleft left moves */
  49.         emulate_key((Schar)KEY_DELETE,nspaces);    /* delete leading spaces if any */
  50.         emulate_key((Schar)KEY_CARRIAGERETURN,1);    /* load cr */
  51.         emulate_key((Schar)KEY_RIGHTARROW,nleft);    /* load nleft right moves */
  52.         emulate_key(keybuf,1);    /* load the character they typed */
  53.         return(1);
  54.     }
  55.     else
  56.         return(0);
  57. }
  58.  
  59.